<?php
define('IN_ADMINCP', TRUE);
define('IN_TESTCP', TRUE);
define('TESTCP_AJAX', AJAX);
define('TESTCP_PATH', dirname(__FILE__));
define('APP_PATH', dirname(TESTCP_PATH));
//echo TESTCP_PATH . '--' . APP_PATH;die;
require APP_PATH . '/app.php';
$admincp = new admincp;
$account = new admincp_account;
//上面的代码采用杨坤的框架，下面的代码采用原生PHP
include 'center/Model.class.php';
include 'center/Route.class.php';
class Article extends Model{
    public $admin='小编';
    public $error='';
    public function Action(){
        if(isset($_POST['submit'])){
            $this->Add();
        }
    }
    private function Add(){
        $data=array(
            'admin'=>"'".$this->admin."'",
            'title'=>"'".$_POST['title']."'",
            'content'=>"'".$_POST['content']."'",
            'time'=>time()
        );
        if(empty($_POST['title']) || empty($_POST['content'])){
            return $this->error="*文章标题与内容不得为空";
        }
        $sql="INSERT INTO oa_article(admin,title,content,create_tim)
                   VALUES ({$data['admin']},
                          {$data['title']},
                          {$data['content']},
                          {$data['time']}
                      )";
        $a=parent::aud($sql);
        if($a==1){
            echo '<script>alert("文档添加成功！");</script>';
        }else{
            echo '<script>alert("文档添加失败！请检查文档！");</script>';
        }
        //Header("Location:".Route::Url('index'));
    }
}
$model=new Article();
$model->Action();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <link rel="stylesheet" type="text/css" href="assets/css/editor.css"/>
    <link rel="stylesheet" type="text/css" href="assets/css/public.css"/>
    <script type="text/javascript" src="assets/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="ueditor/ueditor.all.min.js"> </script>
</head>
<body>
<div id="content">
    <div id="content-box">
        <div class="content-head">
            <div class="keyboard padding-l40">
                <input type="text" class="search padding-l40 color-black" placeholder="站内搜索"/>
                <div class="keyboard-botton">
                    <a href="javascript:void(0);"><img src="assets/backend-img/content-head/settings.png"/></a>
                    <a href="javascript:void(0);"><img src="assets/backend-img/content-head/language.png"/></a>
                    <a href="javascript:void(0);" class="information"><img src="assets/backend-img/content-head/information.png"/></a>
                    <a href="javascript:void(0);" class="on-off"><img src="assets/backend-img/content-head/on-off.png"/></a>
                </div>
            </div>
            <div class="navigation padding-l40">
                <a href="javascript:void(0);">导航管理</a><a href="javascript:void(0);" class="rating">添加文章</a><span>点击富文本编辑器的全屏按钮，可进行全屏模式的编辑。</span>
            </div>
        </div>
        <div class="content">
            <div class="box">
                <form action="" method="post" enctype="multipart/form-data">
                    <div class="width40" style="padding:30px 0 10px 0;">
                        <div style="color:red; padding-bottom:20px;">
                            <?php if($model->error){ echo $model->error;}?>
                        </div>
                        <div>
                            <label>文章标题：</label>
                            <input type="text" name="title" class="input-text" placeholder="请输入文章标题"/>
                            <span style="color:red;">*(必填)</span>
                        </div>
                    </div>
                    <div>
                        <textarea id="editor" style="width:1024px; height:600px; margin-top:25px" name="content"></textarea>
                    </div>
                    <div class="float-l clear width1024">
                        <input type="submit" name="submit" class="submit" value="确认"/>
                        <a href="<?= Route::Url('index')?>" class="undo">取消并返回</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<?php include 'menu.php'?>
<script type="text/javascript">
    //单选框点击样式,这里目前使用面向对象的写法，虽然简单但是过程不好理解，以后将使用foreach遍历的方法
    $('.state-radio').on('click',function(){
        a=$('.radio').val();
        $('.state-radio').removeClass('state-on state-off');
        $('.state-radio').addClass('state-off');
        $(this).removeClass('state-off');
        $(this).addClass('state-on');
        $('.radio').val($(this).attr('name'));
    });
    //首页图片上传按钮
    $('.add-img').click(function(){
        $('.file-img').click();
    });
    //显示缩略图
    $(".file-img").on("change", function(){
        var files = !!this.files ? this.files : [];
        if (!files.length || !window.FileReader) return;
        if (/^image/.test( files[0].type)){
            var reader = new FileReader();
            reader.readAsDataURL(files[0]);
            reader.onloadend = function(){
                $(".add-img").css("background", "url("+this.result+") no-repeat center");
            }
        }
    });
    //实例化编辑器
    var ue = UE.getEditor('editor',{
        toolbars: [
            [
                'undo', //撤销
                'redo', //重做
                'bold', //加粗
                'indent', //首行缩进
                'italic', //斜
                'formatmatch', //格式刷
                'pasteplain', //纯文本粘贴模式
                'time', //时间
                'date', //日期
                'fontsize', //字号
                'paragraph', //段落格式
                'simpleupload', //单图上传
                'insertimage', //多图上传
                'insertvideo', //视频
                'justifyleft', //居左对齐
                'justifyright', //居右对齐
                'justifycenter', //居中对齐
                'justifyjustify', //两端对齐
                'forecolor', //字体颜色
                'backcolor', //背景色
                'fullscreen', //全屏
                'rowspacingtop', //段前距
                'rowspacingbottom', //段后距
                'imagenone', //默认
                'imageleft', //左浮动
                'imageright', //右浮动
                'imagecenter', //居中
                'wordimage', //图片转存
                'lineheight', //行间距
                'edittip ', //编辑提示
                'touppercase', //字母大写
                'tolowercase', //字母小写
            ]
        ]
    });
</script>
</body>
</html>